/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * humanResourceModule.java
 *
 * Created on Oct 22, 2010, 4:20:08 PM
 */

package restaurantmanagementsystem;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.*;

//myVariables
/**
 *
 * @author edwind
 */
public class financeAndAdmin extends javax.swing.JFrame {

    /** Creates new form humanResourceModule */
    public financeAndAdmin() {
        super("Finance And Administration");
        initComponents();
        initDatabase();

        this.setSize(850, 630);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension windowSize = this.getSize();

        int windowX = Math.max(0, (screenSize.width  - windowSize.width ) / 2);
        int windowY = Math.max(0, (screenSize.height - windowSize.height) / 2);

        this.setLocation(windowX, windowY);
        this.setResizable(false);

        getTableInfo();
        inventoryButton.setSelected(true);
        buttonNew.setEnabled(false);
        buttonEdit.setEnabled(false);
        buttonSave.setEnabled(false);
        butttonDelete.setEnabled(false);
        setTable();

        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        mainLayeredPane = new javax.swing.JLayeredPane();
        mainPanel = new javax.swing.JPanel();
        toolbarPanel = new javax.swing.JPanel();
        toolbar = new javax.swing.JToolBar();
        buttonNew = new javax.swing.JButton();
        buttonEdit = new javax.swing.JButton();
        buttonSave = new javax.swing.JButton();
        butttonDelete = new javax.swing.JButton();
        toolbar2 = new javax.swing.JToolBar();
        buttonLogout = new javax.swing.JButton();
        buttonExit = new javax.swing.JButton();
        scrollPane = new javax.swing.JScrollPane();
        table1 = new javax.swing.JTable();
        topPanel = new javax.swing.JPanel();
        toolbar3 = new javax.swing.JToolBar();
        inventoryButton = new javax.swing.JRadioButton();
        assetButton = new javax.swing.JRadioButton();
        vendorButton = new javax.swing.JRadioButton();
        employeeButton = new javax.swing.JRadioButton();
        salesButton = new javax.swing.JRadioButton();
        toolbar4 = new javax.swing.JToolBar();
        searchButton = new javax.swing.JButton();
        searchField = new javax.swing.JTextField();
        bottomPanel = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        mainPanel.setBackground(new java.awt.Color(175, 170, 165));
        mainPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        toolbarPanel.setOpaque(false);

        toolbar.setFloatable(false);
        toolbar.setOrientation(1);
        toolbar.setRollover(true);
        toolbar.setOpaque(false);

        buttonNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/new.png"))); // NOI18N
        buttonNew.setText("New");
        buttonNew.setToolTipText("Add a new record");
        buttonNew.setFocusable(false);
        buttonNew.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonNew.setMaximumSize(new java.awt.Dimension(62, 66));
        buttonNew.setMinimumSize(new java.awt.Dimension(62, 66));
        buttonNew.setPreferredSize(new java.awt.Dimension(62, 66));
        buttonNew.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonNew.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonNewMouseClicked(evt);
            }
        });
        buttonNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonNewActionPerformed(evt);
            }
        });
        toolbar.add(buttonNew);

        buttonEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/edit.png"))); // NOI18N
        buttonEdit.setText("Edit");
        buttonEdit.setToolTipText("Edit a record");
        buttonEdit.setFocusable(false);
        buttonEdit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonEdit.setMaximumSize(new java.awt.Dimension(62, 66));
        buttonEdit.setMinimumSize(new java.awt.Dimension(62, 66));
        buttonEdit.setPreferredSize(new java.awt.Dimension(62, 66));
        buttonEdit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonEdit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonEditMouseClicked(evt);
            }
        });
        toolbar.add(buttonEdit);

        buttonSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/save.png"))); // NOI18N
        buttonSave.setText("Save");
        buttonSave.setToolTipText("Save all changes");
        buttonSave.setFocusable(false);
        buttonSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonSave.setMaximumSize(new java.awt.Dimension(62, 66));
        buttonSave.setMinimumSize(new java.awt.Dimension(62, 66));
        buttonSave.setPreferredSize(new java.awt.Dimension(62, 66));
        buttonSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolbar.add(buttonSave);

        butttonDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/delete.png"))); // NOI18N
        butttonDelete.setText("Delete");
        butttonDelete.setToolTipText("Delete a record");
        butttonDelete.setFocusable(false);
        butttonDelete.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        butttonDelete.setMaximumSize(new java.awt.Dimension(62, 66));
        butttonDelete.setMinimumSize(new java.awt.Dimension(62, 66));
        butttonDelete.setPreferredSize(new java.awt.Dimension(62, 66));
        butttonDelete.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        butttonDelete.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                butttonDeleteMouseClicked(evt);
            }
        });
        butttonDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butttonDeleteActionPerformed(evt);
            }
        });
        toolbar.add(butttonDelete);

        toolbar2.setFloatable(false);
        toolbar2.setOrientation(1);
        toolbar2.setRollover(true);
        toolbar2.setOpaque(false);

        buttonLogout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/logout (1).png"))); // NOI18N
        buttonLogout.setText("Logout");
        buttonLogout.setToolTipText("Log out from your account");
        buttonLogout.setFocusable(false);
        buttonLogout.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonLogout.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonLogout.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonLogoutMouseClicked(evt);
            }
        });
        toolbar2.add(buttonLogout);

        buttonExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exit2.png"))); // NOI18N
        buttonExit.setText("Exit");
        buttonExit.setToolTipText("Close the program");
        buttonExit.setFocusable(false);
        buttonExit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonExit.setMaximumSize(new java.awt.Dimension(62, 66));
        buttonExit.setMinimumSize(new java.awt.Dimension(62, 66));
        buttonExit.setPreferredSize(new java.awt.Dimension(62, 66));
        buttonExit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonExit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonExitMouseClicked(evt);
            }
        });
        toolbar2.add(buttonExit);

        javax.swing.GroupLayout toolbarPanelLayout = new javax.swing.GroupLayout(toolbarPanel);
        toolbarPanel.setLayout(toolbarPanelLayout);
        toolbarPanelLayout.setHorizontalGroup(
            toolbarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, toolbarPanelLayout.createSequentialGroup()
                .addGroup(toolbarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(toolbar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
                    .addComponent(toolbar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        toolbarPanelLayout.setVerticalGroup(
            toolbarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, toolbarPanelLayout.createSequentialGroup()
                .addContainerGap(30, Short.MAX_VALUE)
                .addComponent(toolbar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(94, 94, 94)
                .addComponent(toolbar2, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        mainPanel.add(toolbarPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 70, 600));

        table1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        scrollPane.setViewportView(table1);

        mainPanel.add(scrollPane, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 40, 770, 370));

        toolbar3.setBorder(null);
        toolbar3.setFloatable(false);
        toolbar3.setRollover(true);
        toolbar3.setOpaque(false);
        toolbar3.setVerifyInputWhenFocusTarget(false);

        buttonGroup1.add(inventoryButton);
        inventoryButton.setText("Inventory");
        inventoryButton.setFocusable(false);
        inventoryButton.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        inventoryButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                inventoryButtonMouseClicked(evt);
            }
        });
        inventoryButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inventoryButtonActionPerformed(evt);
            }
        });
        toolbar3.add(inventoryButton);

        buttonGroup1.add(assetButton);
        assetButton.setText("Assets");
        assetButton.setFocusable(false);
        assetButton.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        assetButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        assetButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                assetButtonMouseClicked(evt);
            }
        });
        toolbar3.add(assetButton);

        buttonGroup1.add(vendorButton);
        vendorButton.setText("Vendor");
        vendorButton.setFocusable(false);
        vendorButton.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        vendorButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        vendorButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                vendorButtonMouseClicked(evt);
            }
        });
        toolbar3.add(vendorButton);

        buttonGroup1.add(employeeButton);
        employeeButton.setText("Employee");
        employeeButton.setFocusable(false);
        employeeButton.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        employeeButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                employeeButtonMouseClicked(evt);
            }
        });
        toolbar3.add(employeeButton);

        buttonGroup1.add(salesButton);
        salesButton.setText("Sales");
        salesButton.setFocusable(false);
        salesButton.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        salesButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        salesButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                salesButtonMouseClicked(evt);
            }
        });
        toolbar3.add(salesButton);

        toolbar4.setBorder(null);
        toolbar4.setFloatable(false);
        toolbar4.setRollover(true);
        toolbar4.setOpaque(false);

        searchButton.setText("Search");
        searchButton.setFocusable(false);
        searchButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        searchButton.setMaximumSize(new java.awt.Dimension(70, 20));
        searchButton.setMinimumSize(new java.awt.Dimension(70, 20));
        searchButton.setPreferredSize(new java.awt.Dimension(70, 20));
        searchButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        searchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchButtonActionPerformed(evt);
            }
        });
        toolbar4.add(searchButton);

        searchField.setFont(new java.awt.Font("Ubuntu", 2, 15));
        searchField.setText("Enter Keyword");
        searchField.setMaximumSize(new java.awt.Dimension(200, 20));
        searchField.setMinimumSize(new java.awt.Dimension(200, 20));
        searchField.setPreferredSize(new java.awt.Dimension(200, 20));
        searchField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchFieldActionPerformed(evt);
            }
        });
        searchField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                searchFieldFocusGained(evt);
            }
        });
        searchField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                searchFieldKeyReleased(evt);
            }
        });
        toolbar4.add(searchField);

        javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(topPanel);
        topPanel.setLayout(topPanelLayout);
        topPanelLayout.setHorizontalGroup(
            topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, topPanelLayout.createSequentialGroup()
                .addComponent(toolbar3, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(toolbar4, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        topPanelLayout.setVerticalGroup(
            topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(topPanelLayout.createSequentialGroup()
                .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(toolbar3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE)
                    .addComponent(toolbar4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(370, Short.MAX_VALUE))
        );

        mainPanel.add(topPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 0, 780, 410));

        bottomPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        mainPanel.add(bottomPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 410, 770, 190));

        mainPanel.setBounds(0, 0, 850, 600);
        mainLayeredPane.add(mainPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        getContentPane().add(mainLayeredPane, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 850, 600));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void inventoryButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_inventoryButtonMouseClicked
        setTable();
        getTableInfo();
}//GEN-LAST:event_inventoryButtonMouseClicked

    private void assetButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_assetButtonMouseClicked
        setTable();
        getTableInfo();
}//GEN-LAST:event_assetButtonMouseClicked

    private void vendorButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_vendorButtonMouseClicked
        setTable();
        getTableInfo();
}//GEN-LAST:event_vendorButtonMouseClicked

    private void inventoryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inventoryButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_inventoryButtonActionPerformed

    private void searchFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_searchFieldActionPerformed

    private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_searchButtonActionPerformed

    private void buttonNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNewActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_buttonNewActionPerformed

    private void buttonNewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonNewMouseClicked
        //selectMode = 0;
        //table1.clearSelection();
        // TODO add your handling code here:
       //setEnabled(false);
    }//GEN-LAST:event_buttonNewMouseClicked

    private void buttonEditMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonEditMouseClicked
        // TODO add your handling code here:
       // selectMode = 1;
        //if (table1.getSelectedRow() != -1){
          //  table1.clearSelection();
        //}
        //disableButton();
        //setEnabled(false);
    }//GEN-LAST:event_buttonEditMouseClicked

    private void butttonDeleteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_butttonDeleteMouseClicked
        // TODO add your handling code here:
        //setEnabled(false);
    }//GEN-LAST:event_butttonDeleteMouseClicked

    private void buttonLogoutMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonLogoutMouseClicked
        // TODO add your handling code here:
        this.setVisible(false);
        new mainMenu().setVisible(true);
    }//GEN-LAST:event_buttonLogoutMouseClicked

    private void buttonExitMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonExitMouseClicked
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_buttonExitMouseClicked

    private void searchFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_searchFieldFocusGained
        // TODO add your handling code here:
         if (searchField.getText().equals("Enter Keyword")){
            searchField.setText("");
        }
    }//GEN-LAST:event_searchFieldFocusGained

    private void searchFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchFieldKeyReleased
        // TODO add your handling code here:
         searchSQL();
    }//GEN-LAST:event_searchFieldKeyReleased

    private void salesButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_salesButtonMouseClicked
        setTable();
        getTableInfo();
        // TODO add your handling code here:
    }//GEN-LAST:event_salesButtonMouseClicked

    private void employeeButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_employeeButtonMouseClicked
        setTable();
        getTableInfo();
        // TODO add your handling code here:
    }//GEN-LAST:event_employeeButtonMouseClicked

    private void butttonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butttonDeleteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_butttonDeleteActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new financeAndAdmin().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton assetButton;
    private javax.swing.JPanel bottomPanel;
    private javax.swing.JButton buttonEdit;
    private javax.swing.JButton buttonExit;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton buttonLogout;
    private javax.swing.JButton buttonNew;
    private javax.swing.JButton buttonSave;
    private javax.swing.JButton butttonDelete;
    private javax.swing.JRadioButton employeeButton;
    private javax.swing.JRadioButton inventoryButton;
    private javax.swing.JLayeredPane mainLayeredPane;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JRadioButton salesButton;
    private javax.swing.JScrollPane scrollPane;
    private javax.swing.JButton searchButton;
    private javax.swing.JTextField searchField;
    private javax.swing.JTable table1;
    private javax.swing.JToolBar toolbar;
    private javax.swing.JToolBar toolbar2;
    private javax.swing.JToolBar toolbar3;
    private javax.swing.JToolBar toolbar4;
    private javax.swing.JPanel toolbarPanel;
    private javax.swing.JPanel topPanel;
    private javax.swing.JRadioButton vendorButton;
    // End of variables declaration//GEN-END:variables

    Connection con;
    NewTableModel newTableInventory= new NewTableModel();
    NewTableModel newTableAsset = new NewTableModel();
    NewTableModel newTableVendor = new NewTableModel();
    NewTableModel newTableEmployee = new NewTableModel();
    NewTableModel newTableSales = new NewTableModel();
    int countTable1Row = 0;
    int countTable1Column = 0;
    int countTable2Row = 0;
    int countTable2Column = 0;
    int countTable3Row = 0;
    int countTable3Column = 0;
    int countTable4Row = 0;
    int countTable4Column = 0;
    int countTable5Row = 0;
    int countTable5Column = 0;
    int rowIncrement = 0;
    int columnIncrement = 0;
    String[] vendorMenuItem;
    int selectMode = 0;

    private void initDatabase() {
       try{
            DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
            con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "Edwind", "cat200");
            System.out.println("Database Connected");
        }
        catch(Exception e){
            System.out.println("Cannot connect to database");
        }
    }

    public void getTableInfo() {
        Dimension THIS_SIZE = (mainLayeredPane.getSize());

        table1.setMaximumSize(THIS_SIZE);
        table1.setMinimumSize(THIS_SIZE);
        table1.setPreferredSize(THIS_SIZE);

        countTable1Row = 0;
        countTable1Column = 0;
        countTable2Row = 0;
        countTable2Column = 0;
        countTable3Row = 0;
        countTable3Column = 0;
        countTable4Row = 0;
        countTable4Column = 0;
        countTable5Row = 0;
        countTable5Column = 0;
        rowIncrement = 0;
        columnIncrement = 0;

        try{
            Statement stmt = con.createStatement();
            ResultSet rset = stmt.executeQuery("SELECT* FROM INVENTORY");

            //creating 2d arrays of appropriate size according to database
            while (rset.next()){
                countTable1Row++;
            }

            ResultSetMetaData metadata = rset.getMetaData();
            countTable1Column = metadata.getColumnCount();

            newTableInventory.setDataSize(countTable1Row, countTable1Column);
            newTableInventory.setColumnNameSize();
            //end

            //adding column names to table model
            newTableInventory.setColumnName(0, "Inventory Number");
            newTableInventory.setColumnName(1, "Inventory Name");
            newTableInventory.setColumnName(2, "Quantity");
            newTableInventory.setColumnName(3, "Cost");
            newTableInventory.setColumnName(4, "Vendor Number");
            // end

            rset = stmt.executeQuery("SELECT* FROM INVENTORY");
            while(rset.next()){
                newTableInventory.addString(rowIncrement, columnIncrement, rset.getString("INV_NO"));
                columnIncrement++;
                newTableInventory.addString(rowIncrement, columnIncrement, rset.getString("INV_NAME"));
                columnIncrement++;
                newTableInventory.addString(rowIncrement, columnIncrement, rset.getString("INV_QTY"));
                columnIncrement++;
                newTableInventory.addString(rowIncrement, columnIncrement, rset.getString("INV_COST"));
                columnIncrement++;
                newTableInventory.addString(rowIncrement, columnIncrement, rset.getString("VENDOR_NO"));
                columnIncrement = 0;
                rowIncrement++;
            }

            rowIncrement = 0;
            columnIncrement = 0;

            rset = stmt.executeQuery("SELECT* FROM ASSET");

            //creating 2d arrays of appropriate size according to database
            while (rset.next()){
                countTable2Row++;
            }

            metadata = rset.getMetaData();
            countTable2Column = metadata.getColumnCount();

            newTableAsset.setDataSize(countTable2Row, countTable2Column);
            newTableAsset.setColumnNameSize();
            //end

            //adding column names to table model
            newTableAsset.setColumnName(0, "Asset Number");
            newTableAsset.setColumnName(1, "Asset Name");
             newTableAsset.setColumnName(2, "Asset Quantity");
            newTableAsset.setColumnName(3, "Asset Cost");
            // end

            rset = stmt.executeQuery("SELECT* FROM ASSET");
            while(rset.next()){
                newTableAsset.addString(rowIncrement, columnIncrement, rset.getString("ASSET_NO"));
                columnIncrement++;
                newTableAsset.addString(rowIncrement, columnIncrement, rset.getString("ASSET_NAME"));
                columnIncrement++;
                newTableAsset.addString(rowIncrement, columnIncrement, rset.getString("ASSET_QTY"));
                columnIncrement++;
                newTableAsset.addString(rowIncrement, columnIncrement, rset.getString("ASSET_COST"));
                columnIncrement = 0;
                rowIncrement++;
            }

            rowIncrement = 0;
            columnIncrement = 0;

            rset = stmt.executeQuery("SELECT* FROM VENDOR");

            //creating 2d arrays of appropriate size according to database
            while (rset.next()){
                countTable3Row++;
            }

            metadata = rset.getMetaData();
            countTable3Column = metadata.getColumnCount();

            newTableVendor.setDataSize(countTable3Row, countTable3Column);
            newTableVendor.setColumnNameSize();
            //end

            //adding column names to table model
            newTableVendor.setColumnName(0, "Vendor Number");
            newTableVendor.setColumnName(1, "Vendor Name");
             newTableVendor.setColumnName(2, "Vendor Contact");
            newTableVendor.setColumnName(3, "Person in Charge");
            // end

            rset = stmt.executeQuery("SELECT* FROM VENDOR");
            while(rset.next()){
                newTableVendor.addString(rowIncrement, columnIncrement, rset.getString("VENDOR_NO"));
                columnIncrement++;
                newTableVendor.addString(rowIncrement, columnIncrement, rset.getString("VENDOR_NAME"));
                columnIncrement++;
                newTableVendor.addString(rowIncrement, columnIncrement, rset.getString("VENDOR_CONTACT"));
                columnIncrement++;
                newTableVendor.addString(rowIncrement, columnIncrement, rset.getString("VENDOR_PERSON_IN_CHARGE"));
                columnIncrement = 0;
                rowIncrement++;
            }

            rowIncrement = 0;
            columnIncrement = 0;

            rset = stmt.executeQuery("SELECT* FROM EMPLOYEE");

            //creating 2d arrays of appropriate size according to database
            while (rset.next()){
                countTable4Row++;
            }

            metadata = rset.getMetaData();
            countTable4Column = metadata.getColumnCount();

            newTableEmployee.setDataSize(countTable4Row, countTable4Column);
            newTableEmployee.setColumnNameSize();
            //end

            //adding column names to table model
            newTableEmployee.setColumnName(0, "Employee ID");
            newTableEmployee.setColumnName(1, "Name");
            newTableEmployee.setColumnName(2, "Job");
            newTableEmployee.setColumnName(3, "Branch");
            newTableEmployee.setColumnName(4, "Contact No.");
            newTableEmployee.setColumnName(5, "Address");
            // end

            rset = stmt.executeQuery("SELECT* FROM EMPLOYEE");
            while(rset.next()){
                newTableEmployee.addString(rowIncrement, columnIncrement, rset.getString("EMP_ID"));
                columnIncrement++;
                newTableEmployee.addString(rowIncrement, columnIncrement, rset.getString("EMP_NAME"));
                columnIncrement++;
                newTableEmployee.addString(rowIncrement, columnIncrement, rset.getString("JOB_NO"));
                columnIncrement++;
                newTableEmployee.addString(rowIncrement, columnIncrement, rset.getString("BRANCH_NO"));
                columnIncrement++;
                newTableEmployee.addString(rowIncrement, columnIncrement, rset.getString("EMP_CONTACT_NO"));
                columnIncrement++;
                newTableEmployee.addString(rowIncrement, columnIncrement, rset.getString("EMP_ADDRESS"));
                columnIncrement = 0;
                rowIncrement++;
            }

            rowIncrement = 0;
            columnIncrement = 0;

            rset = stmt.executeQuery("SELECT* FROM SALES");

            //creating 2d arrays of appropriate size according to database
            while (rset.next()){
                countTable5Row++;
            }

            metadata = rset.getMetaData();
            countTable5Column = metadata.getColumnCount();

            newTableSales.setDataSize(countTable5Row, countTable5Column);
            newTableSales.setColumnNameSize();
            //end

            //adding column names to table model
            newTableSales.setColumnName(0, "Sales No.");
            newTableSales.setColumnName(1, "Total Sales");
            newTableSales.setColumnName(2, "Sales Date");
            newTableSales.setColumnName(3, "Branch No.");
            // end

            rset = stmt.executeQuery("SELECT* FROM SALES ");
            while(rset.next()){
                newTableSales.addString(rowIncrement, columnIncrement, rset.getString("SALES_NO"));
                columnIncrement++;
                newTableSales.addString(rowIncrement, columnIncrement, rset.getString("SALES_TOTAL"));
                columnIncrement++;
                newTableSales.addString(rowIncrement, columnIncrement, rset.getString("SALES_DATE").substring(0, 10));
                columnIncrement++;
                newTableSales.addString(rowIncrement, columnIncrement, rset.getString("BRANCH_NO"));
                columnIncrement = 0;
                rowIncrement++;
            }
        }
        catch(Exception e){
            System.out.println("Error connecting to database");
        }

    }
        public void disableButton(){
        buttonNew.setEnabled(false);
        buttonEdit.setEnabled(false);
        buttonSave.setEnabled(false);
       //buttonDelete.setEnabled(false);
    }




    public void setTable(){
        table1.setModel(selectedTable());
        table1.show();
    }

    public NewTableModel selectedTable(){
        
        int n = selectedButton();
        if (n == 0){
            return newTableInventory;
        }
        else if (n == 1){
            return newTableAsset;
        }
        else if (n == 2){
            return newTableVendor;
        }
        else if (n == 3){
            return newTableEmployee;
        }
        else
        return newTableSales;
    }

    private int selectedButton() {

        if (inventoryButton.isSelected()){
            System.out.print("Inventory Table Selected\n");
            return 0;
        }
        else if (assetButton.isSelected()){
            System.out.print("Asset Table Selected\n");
            return 1;
        }
        else if (vendorButton.isSelected()){
            System.out.print("Vendor Table Selected\n");
            return 2;
        }
        else if (employeeButton.isSelected()){
            System.out.print("Employee Table Selected\n");
            return 3;
        }
       //else if (salesButton.isSelected())
        else
        System.out.print("Sales Table Selected\n");
        return 4;



    }

        public void searchSQL(){

        String searchString = "";
        String tempString = searchField.getText();
        int n = selectedButton();


        Dimension THIS_SIZE = (mainLayeredPane.getSize());

        table1.setMaximumSize(THIS_SIZE);
        table1.setMinimumSize(THIS_SIZE);
        table1.setPreferredSize(THIS_SIZE);

        countTable1Row = 0;
        countTable1Column = 0;
        countTable2Row = 0;
        countTable2Column = 0;
        countTable3Row = 0;
        countTable3Column = 0;
        rowIncrement = 0;
        columnIncrement = 0;

        if (n == 0){

            searchString = "SELECT * FROM INVENTORY WHERE INV_NO LIKE '%" + tempString + "%'"
                + " OR INV_NAME LIKE '%" + tempString + "%'"
                + " OR INV_QTY LIKE '%" + tempString + "%'"
                + " OR INV_COST LIKE '%" + tempString + "%'"
                + " OR VENDOR_NO LIKE '%" + tempString + "%'";

            System.out.println(searchString);

            try{
                Statement stmt = con.createStatement();

                ResultSet rset2 = stmt.executeQuery(searchString);

                //creating 2d arrays of appropriate size according to database
                while (rset2.next()){
                    countTable1Row++;
                }

                ResultSetMetaData metadata = rset2.getMetaData();
                countTable1Column = metadata.getColumnCount();

                newTableInventory.setDataSize(countTable1Row, countTable1Column);
                newTableInventory.setColumnNameSize();
                //end

                //adding column names to table model
                newTableInventory.setColumnName(0, "Inventory No.");
                newTableInventory.setColumnName(1, "Inventory Name");
                newTableInventory.setColumnName(2, "Quantity");
                newTableInventory.setColumnName(3, "Cost");
                newTableInventory.setColumnName(4, "Vendor No.");
                

                rset2 = stmt.executeQuery(searchString);

                while(rset2.next()){
                    newTableInventory.addString(rowIncrement, columnIncrement, rset2.getString("INV_NO"));
                    columnIncrement++;
                    newTableInventory.addString(rowIncrement, columnIncrement, rset2.getString("INV_NAME"));
                    columnIncrement++;
                    newTableInventory.addString(rowIncrement, columnIncrement, rset2.getString("INV_QTY"));
                    columnIncrement++;
                    newTableInventory.addString(rowIncrement, columnIncrement, rset2.getString("INV_COST"));
                    columnIncrement++;
                    newTableInventory.addString(rowIncrement, columnIncrement, rset2.getString("VENDOR_NO"));
                    columnIncrement = 0;
                    rowIncrement++;
                }
            }
            catch (Exception e){
                System.out.println("Error connecting to database");
            }

        }
        else if (n == 1){
            searchString = "SELECT * FROM ASSET WHERE ASSET_NO LIKE '%" + tempString + "%'"
                + " OR ASSET_NAME LIKE '%" + tempString + "%'"
                + " OR ASSET_QTY LIKE '%" + tempString + "%'"
                + " OR ASSET_COST LIKE '%" + tempString + "%'";

            System.out.println(searchString);

            try{
                Statement stmt = con.createStatement();

                ResultSet rset2 = stmt.executeQuery(searchString);

                //creating 2d arrays of appropriate size according to database
                while (rset2.next()){
                    countTable2Row++;
                }

                ResultSetMetaData metadata = rset2.getMetaData();
                countTable2Column = metadata.getColumnCount();

                newTableAsset.setDataSize(countTable2Row, countTable2Column);
                newTableAsset.setColumnNameSize();
                //end

                //adding column names to table model
                newTableAsset.setColumnName(0, "Asset No.");
                newTableAsset.setColumnName(1, "Asset Name");
                newTableAsset.setColumnName(2, "Asset Quantity");
                newTableAsset.setColumnName(3, "Asset Cost");
                // end

                rset2 = stmt.executeQuery(searchString);

                while(rset2.next()){
                    newTableAsset.addString(rowIncrement, columnIncrement, rset2.getString("ASSET_NO"));
                    columnIncrement++;
                    newTableAsset.addString(rowIncrement, columnIncrement, rset2.getString("ASSET_NAME"));
                    columnIncrement++;
                    newTableAsset.addString(rowIncrement, columnIncrement, rset2.getString("ASSET_QTY"));
                    columnIncrement++;
                    newTableAsset.addString(rowIncrement, columnIncrement, rset2.getString("ASSET_COST"));
                    columnIncrement = 0;
                    rowIncrement++;
                }
            }
            catch (Exception e){
                System.out.println("Error connecting to database");
            }
        }
        else if (n == 2){
            searchString = "SELECT * FROM VENDOR WHERE VENDOR_NO LIKE '%" + tempString + "%'"
                + " OR VENDOR_NAME LIKE '%" + tempString + "%'"
                + " OR VENDOR_CONTACT LIKE '%" + tempString + "%'"
                + " OR VENDOR_PERSON_IN_CHARGE LIKE '%" + tempString + "%'";

            System.out.println(searchString);

            try{
                Statement stmt = con.createStatement();

                ResultSet rset2 = stmt.executeQuery(searchString);

                //creating 2d arrays of appropriate size according to database
                while (rset2.next()){
                    countTable3Row++;
                }

                ResultSetMetaData metadata = rset2.getMetaData();
                countTable3Column = metadata.getColumnCount();

                newTableVendor.setDataSize(countTable3Row, countTable3Column);
                newTableVendor.setColumnNameSize();
                //end

                //adding column names to table model
                newTableVendor.setColumnName(0, "Vendor No.");
                newTableVendor.setColumnName(1, "Vendor Name");
                newTableVendor.setColumnName(2, "Vendor Contact");
                newTableVendor.setColumnName(3, "Person in Charge");
         
                // end

                rset2 = stmt.executeQuery(searchString);

                while(rset2.next()){
                    newTableVendor.addString(rowIncrement, columnIncrement, rset2.getString("VENDOR_NO"));
                    columnIncrement++;
                     newTableVendor.addString(rowIncrement, columnIncrement, rset2.getString("VENDOR_NAME"));
                    columnIncrement++;
                     newTableVendor.addString(rowIncrement, columnIncrement, rset2.getString("VENDOR_CONTACT"));
                    columnIncrement++;
                    newTableVendor.addString(rowIncrement, columnIncrement, rset2.getString("VENDOR_PERSON_IN_CHARGE"));
                    columnIncrement = 0;
                    rowIncrement++;
                }
            }
            catch (Exception e){
                System.out.println("Error connecting to database");
            }
        }
            else if (n == 3){

            searchString = "SELECT * FROM EMPLOYEE WHERE EMP_ID LIKE '%" + tempString + "%'"
                + " OR EMP_NAME LIKE '%" + tempString + "%'"
                + " OR JOB_NO LIKE '%" + tempString + "%'"
                + " OR BRANCH_NO LIKE '%" + tempString + "%'"
                + " OR EMP_CONTACT_NO LIKE '%" + tempString + "%'"
                + " OR EMP_ADDRESS LIKE '%" + tempString + "%'";

            System.out.println(searchString);

            try{
                Statement stmt = con.createStatement();

                ResultSet rset2 = stmt.executeQuery(searchString);

                //creating 2d arrays of appropriate size according to database
                while (rset2.next()){
                    countTable1Row++;
                }

                ResultSetMetaData metadata = rset2.getMetaData();
                countTable1Column = metadata.getColumnCount();

                newTableEmployee.setDataSize(countTable1Row, countTable1Column);
                newTableEmployee.setColumnNameSize();
                //end

                //adding column names to table model
                newTableEmployee.setColumnName(0, "Employee ID");
                newTableEmployee.setColumnName(1, "Name");
                newTableEmployee.setColumnName(2, "Job");
                newTableEmployee.setColumnName(3, "Branch");
                newTableEmployee.setColumnName(4, "Contact No.");
                newTableEmployee.setColumnName(5, "Address");

                rset2 = stmt.executeQuery(searchString);

                while(rset2.next()){
                    newTableEmployee.addString(rowIncrement, columnIncrement, rset2.getString("EMP_ID"));
                    columnIncrement++;
                    newTableEmployee.addString(rowIncrement, columnIncrement, rset2.getString("EMP_NAME"));
                    columnIncrement++;
                    newTableEmployee.addString(rowIncrement, columnIncrement, rset2.getString("JOB_NO"));
                    columnIncrement++;
                    newTableEmployee.addString(rowIncrement, columnIncrement, rset2.getString("BRANCH_NO"));
                    columnIncrement++;
                    newTableEmployee.addString(rowIncrement, columnIncrement, rset2.getString("EMP_CONTACT_NO"));
                    columnIncrement++;
                    newTableEmployee.addString(rowIncrement, columnIncrement, rset2.getString("EMP_ADDRESS"));
                    columnIncrement = 0;
                    rowIncrement++;
                }
            }
            catch (Exception e){
                System.out.println("Error connecting to database");
            }

        }

        else if(n==4){
            searchString = "SELECT * FROM SALES WHERE SALES_NO LIKE '%" + tempString + "%'"
                + " OR SALES_TOTAL LIKE '%" + tempString + "%'"
                + " OR SALES_DATE LIKE '%" + tempString + "%'"
                + " OR BRANCH_NO LIKE '%" + tempString + "%'";

            System.out.println(searchString);

            try{
                 Statement stmt = con.createStatement();
            ResultSet rset2 = stmt.executeQuery(searchString);

            //creating 2d arrays of appropriate size according to database
            while (rset2.next()){
                countTable1Row++;
            }

            ResultSetMetaData metadata = rset2.getMetaData();
            countTable1Column = metadata.getColumnCount();

            newTableSales.setDataSize(countTable1Row, countTable1Column);
            newTableSales.setColumnNameSize();
            //end

            //adding column names to table model
            newTableSales.setColumnName(0, "Sales No.");
            newTableSales.setColumnName(1, "Total Sales");
            newTableSales.setColumnName(2, "Sales Date");
            newTableSales.setColumnName(3, "Branch No.");
            // end

            rset2 = stmt.executeQuery(searchString);
            while(rset2.next()){
                newTableSales.addString(rowIncrement, columnIncrement, rset2.getString("SALES_NO"));
                columnIncrement++;
                newTableSales.addString(rowIncrement, columnIncrement, rset2.getString("SALES_TOTAL"));
                columnIncrement++;
                newTableSales.addString(rowIncrement, columnIncrement, rset2.getString("SALES_DATE").substring(0,10));
                columnIncrement++;
                newTableSales.addString(rowIncrement, columnIncrement, rset2.getString("BRANCH_NO"));
                columnIncrement = 0;
                rowIncrement++;
            }
            }
            catch (Exception e){
                System.out.println("Error connecting to database");
            }
        }

        setTable();
        table1.repaint();


    }
}





        
       


